<?
layout("/inc/win_layout.html",{title:sysTitle}){
?>
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
<div id="page-wrapper" style="margin-left: 0px;margin-top: 0px;">

	<!--BEGIN CONTENT-->
	<div class="page-content"
		style="min-height: auto;padding-bottom: 20px; height: 590px; overflow: auto;">

		<div class="row mbl">
			<input id="balance" type="hidden" class="form-control" value="0" />
			<input id="payment" type="hidden" class="form-control" value="0" />
			<div class="panel">
				<div class="panel-body pan">

					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style="width: 475px; float:left; margin-right:-20px; display:inline;">
							<label for="inputTargetname" class="col-md-3 control-label">指标名称
								<span class='require' >*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="analysisChartName" type="text" class="form-control" value="" />
								</div>
							</div>
						</div>
						<div id = "passwordParent" class="col-lg-6"
							style="width: 460px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">分析字段
								<span class='require' id="yonghu">*</span> </label>
							<div class="input-group input-group-sm mbs" style="margin-left: 15px;">
								<input  id="analyzeZhName" type="text"  value="" class="form-control" disabled="true" /> 
								<span class="input-group-btn">
									<button onclick="analysisCondition()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
								</span> 
								<input id="analyzeEnName" type="hidden" value="0" class="form-control" />
							</div>
						</div>
					</div>
					
					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style="width: 250px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">
						 		<div align="right">是否开启数值统计
									<span class='require' id="paixu">*</span></div>
		                   	 </label>
							<div class="col-md-9" style="width:120px;>
								<div class="input-icon">
									<select id="stauts" class="form-control">
										<option value="0">开启</option>
										<option value="1">关闭</option>
									</select>
									
								</div>
						</div>
						
						
						
											<div class="col-lg-6"
												style="width: 250px; float:left; margin-right:-20px; display:inline;">
												<label for="inputUsername" class="col-md-3 control-label">
											 		<div align="right">图表类型
														<span class='require' id="paixu">*</span></div>
							                   	 </label>
							                   	 <div class="col-md-9" style="width:120px;>
													<div class="input-icon" >
														 <select id="chartGraph" class="form-control" style="width: 100%;" onchange="selectGraph(this.options[this.options.selectedIndex].value)">
															<option selected = "selected" value="broken">折线图</option>
															<option value="pie">饼图</option>
															<option value="bar">柱状图</option>
															<option value="circular">关系图</option>
															<option value="force">力导向图</option>
															<option value="funnel">漏斗图</option>
															<option value="radar">雷达图</option>
															<option value="tendency">趋势图</option>
															<option value="china">中国图</option>
															<option value="world">世界图</option>
														</select> 
													</div>
												</div>
											</div>
					
					<div class="row" style="margin-bottom: 10px;">
					    <div class="panel-body pan ">
					        <div class="profile">
					            <div class="user-info">
					                <div style="margin-bottom: -15px" class="row">
					                    <div class="col-xs-8 text-center" style="margin-left: 76px;">
					                        <figure><img src="images/analysis-broken.jpg" id="chartImg" alt="" style="display: inline-block" class="img-responsive" />
					                        </figure>
					                    </div>
					                </div>
					            </div>
					        </div>
					    </div>
					</div>					
										
										</div>
									</div>
								  </div>
							</div>
						</div>
					</div>

				</div>
			</div>
		</div>
	</div>
	<!--END CONTENT-->
</div>


<?} ?>
<script>
	function selectGraph(graph){
		if(graph != ""){
			$("#chartImg").attr("src","images/analysis-"+graph+".jpg")
		}
	}
	var screen = "radio"
	function getscreen() {
		return screen;
	}
	function getQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var recommendClassEns = window.parent.window[winName].getlibraryEnChoose();
	var tId = window.parent.window[winName].getGraphId();
	var pId = window.parent.window[winName].getId();
	var chartId = window.parent.window[winName].getChartId();
	function getlibraryEnChoose() {
		return recommendClassEns;
	}
	
	/*页面加载完成后加载*/
	$(function(){
		if(tId != 0 ){
			$.ajax({
				type : "post",
				url : "./chartUpdateShow.do",
				data : {
					"id" : tId,
					"repositoryId":recommendClassEns
				},
				dataType : "json",
				async : false,
				success : function(data) {
					if(data[0].msg == "OK"){
						$("#analysisChartName").val(data[0].data.chartName);
						$("#analyzeEnName").val(data[0].data.analyzeEnName);
						$("#analyzeZhName").val(data[0].data.analyzeZhName);
						$("#stauts").val(data[0].data.stauts);
						$("#chartGraph").val(data[0].data.chartType);
						$("#chartImg").attr("src","images/analysis-"+data[0].data.chartType+".jpg")
					}else{
						alert("请求失败");
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	})
	
	
	/*筛选条件*/
	
	function analysisCondition() {
		/* recommendClassEns = $("#recommendClassEn").val(); */
		parent.layer.open({
			type : 2,
			area : [ '450px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"推荐知识库",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["analysis-condition-recommendClass-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	var index = parent.layer.getFrameIndex(window.name);
	function saveChart(){
		if($.trim($("#analysisChartName").val()).length<1){
			alert("请输入指标名称");
			return null;
		}
		if($.trim($("#analyzeEnName").val()).length<2){
			alert("请选择要分析的字段");
			return null;
		}
		if(tId == 0){
			$.ajax({
				type : "post",
				url : "./analysisSaveChart.do",
				data : {
					"id":tId,
					"pId":pId,
					"analysisChartName": $("#analysisChartName").val(),
					"analyzeEnName":$("#analyzeEnName").val(),
					"stauts":$("#stauts").val(),
					"chartGraph":$("#chartGraph").val(),
					"repositoryId":recommendClassEns
				},
				dataType : "json",
				async : false,
				success : function(data) {
					var content = "";
					if(data[0].msg=="OK"){
						/* if(pId !=0){
							chartId = chartId+";";
						} */
						chartId+=data[0].data[0].analysisId+";";
						content+='<div class="col-xs-6">';
						content+='<div class="panel">';
						content+='<div class="panel-body pan">';
						content+='<div class="profile">';
						content+='<div class="user-info" style="border: solid #999 1px;">';
						content+='<div style="margin-bottom: -15px" class="row">';
						content+='<div class="col-xs-6">';
						content+='<p>指标名称:&nbsp;&nbsp;'+data[0].data[0].analysisChartName+'</p>';
						content+='<p>分析字段:&nbsp;&nbsp;'+data[0].data[0].analyzeZhName+'</p>';
						content+='<p>图表类型:&nbsp;&nbsp;'+data[0].data[0].analyzeChartZh+'</p>';
						content+='<p>是否开启对比分析:&nbsp;&nbsp;'+data[0].data[0].analyzeStauts+'</p>';
						content+='<p>操作:';
						content+=' <button class="btn btn-sm btn-info" onclick="analysisAnalyze('+data[0].data[0].analysisId+')">编辑</button>';
						content+='&nbsp;<button class="btn btn-sm btn-primary" onclick="delChart('+data[0].data[0].analysisId+')">删除</button>';
						content+='</p>';
						content+='</div>';
						content+='<div class="col-xs-6 text-center">';
						content+='<figure><img src="images/analysis-'+data[0].data[0].analyzeChartEn+'.jpg" alt="" style="display: inline-block" class="img-responsive" />';
						content+='</figure>';
						content+='</div>';
						content+='</div>';
						content+='</div>';
						content+='</div>';
						content+='</div>';
						content+='</div>';
						content+='</div>';
						window.parent.window[winName].$("#chartParent").append(content);
						window.parent.window[winName].$("#chartId").val(chartId);
						parent.layer.close(index);
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}else{
			$.ajax({
				type : "post",
				url : "./analysisUpdateChart.do",
				data : {
					"id":tId,
					"pId":pId,
					"analysisChartName": $("#analysisChartName").val(),
					"analyzeEnName":$("#analyzeEnName").val(),
					"stauts":$("#stauts").val(),
					"chartGraph":$("#chartGraph").val(),
					"repositoryId":recommendClassEns,
					"chartId":chartId
				},
				dataType : "json",
				async : false,
				success : function(data) {
					var content = "";
					if(data[0].msg=="OK"){
						for(var i = 0; i<data[0].data.length;i++){
							content+='<div class="col-xs-6">';
							content+='<div class="panel">';
							content+='<div class="panel-body pan">';
							content+='<div class="profile">';
							content+='<div class="user-info" style="border: solid #999 1px;">';
							content+='<div style="margin-bottom: -15px" class="row">';
							content+='<div class="col-xs-6">';
							content+='<p>指标名称:&nbsp;&nbsp;'+data[0].data[i].chartName+'</p>';
							content+='<p>分析字段:&nbsp;&nbsp;'+data[0].data[i].analyzeZhName+'</p>';
							content+='<p>图表类型:&nbsp;&nbsp;'+data[0].data[i].analyzeChart+'</p>';
							content+='<p>是否开启对比分析:&nbsp;&nbsp;'+data[0].data[i].analyzeStauts+'</p>';
							content+='<p>操作:';
							content+=' <button class="btn btn-sm btn-info" onclick="analysisAnalyze('+data[0].data[i].analysisId+')">编辑</button>';
							content+='&nbsp;<button class="btn btn-sm btn-primary" onclick="delChart('+data[0].data[i].analysisId+')">删除</button>';
							content+='</p>';
							content+='</div>';
							content+='<div class="col-xs-4 text-center">';
							content+='<figure><img src="images/analysis-'+data[0].data[i].chartType+'.jpg" alt="" style="display: inline-block" class="img-responsive" />';
							content+='</figure>';
							content+='</div>';
							content+='</div>';
							content+='</div>';
							content+='</div>';
							content+='</div>';
							content+='</div>';
							content+='</div>';
						}
							window.parent.window[winName].$("#chartParent").html("");
							window.parent.window[winName].$("#chartParent").append(content);
							window.parent.window[winName].$("#chartId").val(chartId);
							parent.layer.close(index);
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
</script>